"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var BaseDao_1 = require('./BaseDao');
var DocsDao = (function (_super) {
    __extends(DocsDao, _super);
    function DocsDao() {
        _super.call(this);
        this.docModel = this.dbManager.getModel("mDoc");
    }
    DocsDao.prototype.add = function (doc, callback) {
        var doc_ = new this.docModel(doc);
        doc_.save(callback);
    };
    DocsDao.prototype.get = function (docId, callback) {
        this.docModel.findOne({ _id: docId }).populate("project").populate("group").exec(callback);
    };
    DocsDao.prototype.getsByProjectId = function (id, callback) {
        this.docModel.find({ project: id }).populate("project").populate("group").exec(callback);
    };
    DocsDao.prototype.getsByGroudId = function (id, callback) {
        this.docModel.find({ group: id }).exec(callback);
    };
    DocsDao.prototype.updateDoc = function (doc, callback) {
        var query = { _id: doc._id };
        var updater = {
            name: doc.name,
            action: doc.action,
            description: doc.description,
            params: doc.params,
            resps: doc.resps,
            httpMethod: doc.httpMethod,
            url: doc.url,
            group: doc.group
        };
        this.docModel.update(query, updater).exec(callback);
    };
    DocsDao.prototype.delete = function (docId, callback) {
        this.docModel.remove({ _id: docId }).exec(callback);
    };
    return DocsDao;
}(BaseDao_1.BaseDao));
exports.DocsDao = DocsDao;
